package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.craft.CraftController;
import gatperdut.chato.core.interpreter.actions.generic.Action;
import gatperdut.chato.core.interpreter.grammar.comminfo.CraftInfo;
import gatperdut.chato.core.threads.CraftThread;

public class CraftAction extends Action {

    public CraftAction( CraftInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        CraftController cc = getEntityController().getChatoServer().getCraftHandler().findCraftController( getInfo().getCommand() );
        if ( cc == null ) {
            getEntityController().tx( "You don't know that craft." );
            return CommandExecutionResult.OK;
        }

        CraftThread craftThread = new CraftThread( getEntityController(), cc );

        getEntityController().setCraftThread( craftThread );

        craftThread.start();

        return CommandExecutionResult.OK;
    }

    @Override
    public CraftInfo getInfo() {
        return (CraftInfo) super.getInfo();
    }

    @Override
    public boolean interruptsCrafting() {
        return true;
    }

}
